package com.ruoyi.member.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.member.domain.MemberPointsLog;
import com.ruoyi.member.service.IMemberPointsLogService;

/**
 * 积分记录Controller
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/member/points/log")
public class MemberPointsLogController extends BaseController {
    @Autowired
    private IMemberPointsLogService memberPointsLogService;

    /**
     * 获取积分记录列表
     */
    @PreAuthorize("@ss.hasPermi('member:points:list')")
    @GetMapping("/list")
    public TableDataInfo list(MemberPointsLog memberPointsLog) {
        startPage();
        List<MemberPointsLog> list = memberPointsLogService.selectMemberPointsLogList(memberPointsLog);
        return getDataTable(list);
    }

    /**
     * 获取会员积分记录列表
     */
    @PreAuthorize("@ss.hasPermi('member:points:list')")
    @GetMapping("/member/{memberId}")
    public AjaxResult getMemberPointsLogs(@PathVariable("memberId") Long memberId) {
        return success(memberPointsLogService.selectMemberPointsLogByMemberId(memberId));
    }

    /**
     * 根据记录编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('member:points:query')")
    @GetMapping(value = "/{logId}")
    public AjaxResult getInfo(@PathVariable("logId") Long logId) {
        return success(memberPointsLogService.selectMemberPointsLogById(logId));
    }

    /**
     * 新增积分记录
     */
    @PreAuthorize("@ss.hasPermi('member:points:add')")
    @Log(title = "积分记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody MemberPointsLog memberPointsLog) {
        memberPointsLog.setCreateBy(getUsername());
        memberPointsLog.setOperator(getUsername());
        return toAjax(memberPointsLogService.insertMemberPointsLog(memberPointsLog));
    }

    /**
     * 修改积分记录
     */
    @PreAuthorize("@ss.hasPermi('member:points:edit')")
    @Log(title = "积分记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody MemberPointsLog memberPointsLog) {
        memberPointsLog.setUpdateBy(getUsername());
        memberPointsLog.setOperator(getUsername());
        return toAjax(memberPointsLogService.updateMemberPointsLog(memberPointsLog));
    }

    /**
     * 删除积分记录
     */
    @PreAuthorize("@ss.hasPermi('member:points:remove')")
    @Log(title = "积分记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{logIds}")
    public AjaxResult remove(@PathVariable Long[] logIds) {
        return toAjax(memberPointsLogService.deleteMemberPointsLogByIds(logIds));
    }

    /**
     * 清空会员积分记录
     */
    @PreAuthorize("@ss.hasPermi('member:points:remove')")
    @Log(title = "积分记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/clean/{memberId}")
    public AjaxResult clean(@PathVariable("memberId") Long memberId) {
        return toAjax(memberPointsLogService.cleanMemberPointsLog(memberId));
    }
} 